//
// Created by hkkzzxz on 24-8-31.
//

#ifndef YUNSHI_HTTPROUTER_H
#define YUNSHI_HTTPROUTER_H

// 路由处理类

#include "Singleton.h"
#include "HttpConnection.h"

class HttpRouter : public Singleton<HttpRouter> {
    friend class Singleton<HttpRouter>;

public:
    // 传递POST请求
    void POSTSelect(http::request<http::dynamic_body> &httpRequest,
                    http::response<http::dynamic_body> &httpResponse);

    // 传递GET请求
    void GETSelect(http::request<http::dynamic_body> &httpRequest,
                   http::response<http::dynamic_body> &httpResponse);

private:
    HttpRouter();

    ~HttpRouter() {};

    // POST路由表
    std::unordered_map<std::string, std::function
            <void(std::string &, http::request<http::dynamic_body> &,
                  http::response<http::dynamic_body> &)>> postRouteMap;
    // GET路由表
    std::unordered_map<std::string, std::function
            <void(std::string &, http::request<http::dynamic_body> &,
                  http::response<http::dynamic_body> &)>> getRouteMap;

    // 根据身份信息进行路由控制
    bool handleAuthorization(http::request<http::dynamic_body> &httpRequest,
                             http::response<http::dynamic_body> &httpResponse,
                             const std::string &target, std::string &id);
};


#endif //YUNSHI_HTTPROUTER_H
